package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.aliyun.iot20180120.models.DeleteDeviceRequest;
import com.aliyun.iot20180120.models.QueryDeviceDetailRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.vo.DeviceVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 设备管理Controller
 *
 * @author 小新IP归属中国
 * @date 2025-06-28
 */
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "设备管理的接口")
public class DeviceController extends BaseController {
    @Autowired
    private IDeviceService deviceService;


    /***
     * 查询设备管理列表
     * @param device
     * @return
     */

    @ApiOperation("查询设备管理列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(Device device) {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    /***
     * 同步产品列表
     */
    @ApiOperation("同步产品列表")
    @PostMapping("/syncProductList")
    public AjaxResult syncProductList() throws Exception {

        deviceService.syncProductList();
        return AjaxResult.success();
    }

    /***
     * 查询所有产品列表
     */
    @ApiOperation("查询所有产品列表")
    @GetMapping("/allProduct")
    public AjaxResult allProduct() {
        return AjaxResult.success(deviceService.allProduct());
    }

    /***
     * 注册设备
     * @param dto
     * @return
     */

    @ApiOperation("注册设备")
    @PostMapping("/register")
    public AjaxResult register(DeviceDto dto) {
        deviceService.register(dto);
        return AjaxResult.success();
    }

    /***
     * 查询设备详细数据
     * @param dto
     * @return
     */
    @ApiOperation("查询设备详细数据")
    @PostMapping("/queryDeviceDetail")
    public AjaxResult queryDeviceDetail(@RequestBody DeviceDto dto) {
        DeviceVo deviceVo = deviceService.queryDeviceDetail(dto);
        return AjaxResult.success(deviceVo);
    }


    /***
     * 查询指定设备的物模型运行状态
     * @param request
     * @return
     */
    @ApiOperation("查询指定设备的物模型运行状态")
    @PostMapping("/queryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {

        return deviceService.queryDevicePropertyStatus(request);
    }

    /***
     * 查看指定产品的已发布物模型中的功能定义详情
     * @param request
     * @return
     */
    @ApiOperation("查看指定产品的已发布物模型中的功能定义详情")
    @PostMapping("/queryThingModelPublished")
    public AjaxResult queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        return deviceService.queryThingModelPublished(request);
    }


    /***
     * 删除设备
     * @param dto
     * @return
     */
    @ApiOperation("删除设备")
    @DeleteMapping
    public AjaxResult deleteDevice(DeviceDto dto){
        deviceService.deleteDevice(dto);
        return AjaxResult.success();
    }

    @PutMapping
    @ApiOperation("修改设备")
    public AjaxResult updateDevice(DeviceDto dto){

        return deviceService.updateDevice(dto);

    }



}
